//
//  main.m
//  StringDemo
//
//  Created by zhouxiaobo on 15/10/23.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        NSString *Str1 = @"0123456789";
        NSString *Str2 = @"0123456789";
        NSString *Str3 = @"012";
        
        BOOL flag1 = [Str1 isEqualToString:Str2];
        NSLog(@"%d",flag1);
        
        BOOL flag2 = [Str1 isEqualToString:Str3];
        NSLog(@"%d",flag2);
        
        NSComparisonResult result = [Str1 compare:Str2];
        if(NSOrderedAscending == result){
            NSLog(@"Str1 < Str2");
        }else if(NSOrderedDescending == result){
            NSLog(@"Str1 > Str2");
        }else if(NSOrderedSame == result){
            NSLog(@"Str1 = Str2");
        }
        
        NSString *Str4 = [Str1 substringFromIndex:4];
        NSLog(@"%@",Str4);
        
        NSString *Str5 = [Str1 substringToIndex:4];
        NSLog(@"%@",Str5);
        
        NSString *Str6 = [Str1 substringWithRange:NSMakeRange(3, 5)];
        NSLog(@"%@",Str6);
        
        NSRange range = [Str1 rangeOfString:Str3];
        NSLog(@"共%zd，在%zd的位置", range.length, range.location);
        
        //----------------------------------------------------------------------------//
        
        NSMutableString *mStr1 = [[NSMutableString alloc]initWithString:Str1];
        NSMutableString *mStr2 = [NSMutableString stringWithString:Str1];
        
        NSMutableString *mStr3 = [[NSMutableString alloc]initWithUTF8String:"hello world"];
        NSMutableString *mStr4 = [NSMutableString stringWithUTF8String:"hello world"];
        
        NSMutableString *mStr5 = [[NSMutableString alloc]initWithFormat:@"hello %@",@"world"];
        NSMutableString *mStr6 = [NSMutableString stringWithFormat:@"hello %@",@"world"];
        
        NSLog(@"%@",mStr1);
        NSLog(@"%@",mStr2);
        NSLog(@"%@",mStr3);
        NSLog(@"%@",mStr4);
        NSLog(@"%@",mStr5);
        NSLog(@"%@",mStr6);
        
        [mStr1 appendString:@" Object c"];  //字符串添加
        NSLog(@"%@",mStr1);
        
        [mStr1 appendFormat:@" love %@", @"you"];
        NSLog(@"%@",mStr1);
        
        [mStr1 insertString:@" 0000" atIndex:4];  //字符串插入
        NSLog(@"%@",mStr1);
        
        [mStr1 deleteCharactersInRange:NSMakeRange(2, 3)];  //字符串删除
        NSLog(@"%@",mStr1);
        
        [mStr1 deleteCharactersInRange:(NSRange){4,2}]; //NSRange另一种定义
        NSLog(@"%@",mStr1);
        
        NSMutableString *mStr7 = [NSMutableString stringWithUTF8String:"love"];  //查询
        NSRange range2 = [mStr1 rangeOfString:mStr7];
        NSLog(@"共%zd，在%zd的位置", range2.length, range2.location);
        
        [mStr1 replaceCharactersInRange:(NSRange){3,5} withString:@"8888"];  //修改字符串
        NSLog(@"%@",mStr1);
    }
    return 0;
}
